package architect.datastructure;

/**
 * 栈的数组实现
 *
 * @author guanxin
 * @date 2018/5/7 10:27
 */

public class ArrayStack {
    // 栈内元素的最大个数
    int maxSize;

    // 栈数组
    Object[] arr;

    // 栈顶元素的下标
    int top;

    public ArrayStack() { }

    public ArrayStack(int maxSize) {
        this.maxSize = maxSize;
        top = -1;
        arr = new Object[maxSize];
    }

    // 压栈
    public void push(Object e) {
        arr[++top] = e;
    }

    // 弹栈
    public Object pop() {
        return arr[top--];
    }

    // 获取而不弹出
    public Object peek() {
        return arr[top];
    }

    // 是否为空
    public boolean isEmpty() {
        return top == -1;
    }

    // 是否已满
    public boolean isFull() {
        return ((top + 1) == this.maxSize);
    }

    public static void main(String[] args) {

    }
}
